<?php

namespace App\Http\Controllers\Wechat;

use WechatService;
use App\Http\Controllers\Controller;
use EasyWeChat\Foundation\Application;

class BaseController extends Controller
{

    /**
     * @var Application
     */
    protected $app;

    /**
     * @var array
     */
    private $option;

    public function __construct($option = null)
    {
        $this->option = $option;

        $this->initApplication();
    }

    protected function initApplication()
    {
        $this->app = app('wechat');
    }

    protected function setOptions($option)
    {
        $this->option = $option;
        $this->app = WechatService::getApp($option);
    }

    protected function setOption($option)
    {
        array_merge($this->option, $option);
        $this->app = WechatService::getApp($option);
    }

    /**
     * @param $value
     *
     *
     * @return mixed
     */
    public function __get($value)
    {
        return $this->app->$value;
    }
}
